package com.itheima.springboot_init.controller;

import com.itheima.springboot_init.domain.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;


@RestController
public class HelloController {


    @Value("${person.name}")
    private String name1;

    @Value("${person.address[0]}")
    private String address1;

    @Value("${msg1}")
    private String msg1;

    @Value("${msg2}")
    private String msg2;

    @Autowired
    private Person person;

    @Autowired
    private Environment environment;

    @RequestMapping("/hello")
    public ModelAndView hello(ModelAndView modelAndView) {
        modelAndView.addObject("name", name1);
        modelAndView.setViewName("success");
        System.out.println(name1);
        System.out.println(address1);

        System.out.println(msg1);
        System.out.println(msg2);

        System.out.println("----------------------------");
        System.out.println(person);

        System.out.println("===============");
        System.out.println(environment.getProperty("name"));
        System.out.println(environment.getProperty("person.age"));
        System.out.println(environment.getProperty("person.address[0]"));

        return modelAndView;
    }
}
